<template>
  <div class="app-container">
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.name"
          size="small"
          clearable
          placeholder="输入供应商名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>

    <el-row :gutter="15">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <el-card class="box-card" shadow="never">
          <div slot="header" class="clearfix">
            <span class="role-span">项目列表</span>
          </div>
          <el-table
            ref="table"
            v-loading="crud.loading"
            highlight-current-row
            style="width: 100%;"
            :data="crud.data"
            @selection-change="crud.selectionChangeHandler"
            border
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column prop="name" label="招标项目名称" />
            <el-table-column prop="code" label="招标项目编号" width="130" />
            <el-table-column prop="status" label="招标项目状态" width="130" />
            <el-table-column prop="contact" label="招标项目联系人" width="150" />
            <el-table-column prop="createBy" label="创建者" width="100" />
            <el-table-column prop="createTime" label="创建日期" width="150px">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="updateTime" label="更新时间" width="150">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="110">
              <template slot-scope="scope">
                <router-link :to="{ name: 'ProjectProcess', query: { pid: scope.row.id } }">
                  <el-button>进度查看</el-button>
                </router-link>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <pagination />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import CRUD, { presenter, header, form, crud } from '@crud/crud';
  import rrOperation from '@crud/RR.operation';
  import crudOperation from '@crud/CRUD.operation';
  import pagination from '@crud/Pagination';
  import ProjectRequest from '@/api/project';

  const defaultForm = {
    name: null,
  };

  export default {
    name: 'ProjectList',
    components: { pagination, crudOperation, rrOperation },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    cruds() {
      return CRUD({
        title: '招标项目',
        url: 'api/project/all',
        sort: 'desc',
        optShow: {
          add: true,
          edit: true,
          del: true,
          reset: true,
        },
        crudMethod: { ...ProjectRequest },
      });
    },
    data() {
      return {
        permission: {
          add: ['admin', 'project:add'],
          edit: ['admin', 'project:edit'],
          del: ['admin', 'project:del'],
        },
      };
    },
    methods: {
      [CRUD.HOOK.beforeToAdd]() {
        this.$router.push({
          name: 'PlanList',
        });
      },
      [CRUD.HOOK.afterToEdit]() {
        this.$router.push({
          name: 'ProjectProfile',
          query: {
            pid: this.crud.selections[0].id,
          },
        });
      },
    },
  };
</script>
